﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Xml;
using System.IO;
using HtmlAgilityPack;
using System.Text;
using System.Net;
/// <summary>
/// Summary description for ExchangeVietComBank
/// </summary>
/// 
namespace WorldExchange
{
    public class ExchangeVietComBank : Exchange
    {
        public ExchangeVietComBank()
        {
            this.LinkService = ConfigurationSettings.AppSettings["Vietcombank"].ToString();
        }
        public ExchangeVietComBank(string pUrl)
        {
            this.LinkService = pUrl;
        }
        #region "Method"
        public override void getExchange()
        {
            Boolean ret = true;

            # region "Gán Giá trị"
            Price a = new Price();
            a.Ma = "";
            a.Mua_CK = "";
            a.Mua_TM = "";
            a.Ban = "";
            AUD = a;
            CAD = a;
            CHF = a;
            DKK = a;
            EUR = a;
            GBP = a;
            HKD = a;
            INR = a;
            JPY = a;
            KRW = a;
            KWD = a;
            MYR = a;
            NOK = a;
            SEK = a;
            SGD = a;
            THB = a;
            USD = a;
            #endregion
            XmlDocument xmldoc = new XmlDocument();
            try
            {
                //VNS.Web.HttpWeb webGet = new VNS.Web.HttpWeb();
                string strXML = WebTool.getWebClient(this.LinkService);
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(strXML);
                // doc2.SelectSingleNode("[Exrate[@CurrencyCode='USD']");



                # region "Gán Giá trị"
                Price TempAUD = new Price();
                XmlNode AUDNode = doc.SelectSingleNode("ExrateList/Exrate[@CurrencyCode='AUD']");
                TempAUD.Ma = "AUD";
                TempAUD.Mua_CK = AUDNode.Attributes["Buy"].Value;
                TempAUD.Mua_TM = AUDNode.Attributes["Transfer"].Value;
                TempAUD.Ban = AUDNode.Attributes["Sell"].Value;
                AUD = TempAUD;

                Price TempCAD = new Price();
                XmlNode CADNode = doc.SelectSingleNode("ExrateList/Exrate[@CurrencyCode='CAD']");
                TempCAD.Ma = "CAD";
                if (CADNode != null)
                {
                    TempCAD.Mua_CK = CADNode.Attributes["Buy"].Value;
                    TempCAD.Mua_TM = CADNode.Attributes["Transfer"].Value;
                    TempCAD.Ban = CADNode.Attributes["Sell"].Value;
                }
                CAD = TempCAD;

                Price TempCHF = new Price();
                XmlNode CHFNode = doc.SelectSingleNode("ExrateList/Exrate[@CurrencyCode='CHF']");
                TempCHF.Ma = "CHF";
                if (CHFNode != null)
                {
                    TempCHF.Mua_CK = CHFNode.Attributes["Buy"].Value;
                    TempCHF.Mua_TM = CHFNode.Attributes["Transfer"].Value;
                    TempCHF.Ban = CHFNode.Attributes["Sell"].Value;
                }
                CHF = TempCHF;

                Price TempDKK = new Price();
                XmlNode DKKNode = doc.SelectSingleNode("ExrateList/Exrate[@CurrencyCode='DKK']");
                TempDKK.Ma = "DKK";
                if (DKKNode != null)
                {
                    TempDKK.Mua_CK = DKKNode.Attributes["Buy"].Value;
                    TempDKK.Mua_TM = DKKNode.Attributes["Transfer"].Value;
                    TempDKK.Ban = DKKNode.Attributes["Sell"].Value;
                }
                DKK = TempDKK;

                Price TempEUR = new Price();
                XmlNode EURNode = doc.SelectSingleNode("ExrateList/Exrate[@CurrencyCode='EUR']");
                TempEUR.Ma = "EUR";
                if (EURNode != null)
                {
                    TempEUR.Mua_CK = EURNode.Attributes["Buy"].Value;
                    TempEUR.Mua_TM = EURNode.Attributes["Transfer"].Value;
                    TempEUR.Ban = EURNode.Attributes["Sell"].Value;
                }
                EUR = TempEUR;

                Price TempGBP = new Price();
                XmlNode GBPNode = doc.SelectSingleNode("ExrateList/Exrate[@CurrencyCode='GBP']");
                TempGBP.Ma = "GBP";
                if (GBPNode != null)
                {
                    TempGBP.Mua_CK = GBPNode.Attributes["Buy"].Value;
                    TempGBP.Mua_TM = GBPNode.Attributes["Transfer"].Value;
                    TempGBP.Ban = GBPNode.Attributes["Sell"].Value;
                }
                GBP = TempGBP;

                Price TempHKD = new Price();
                XmlNode HKDNode = doc.SelectSingleNode("ExrateList/Exrate[@CurrencyCode='HKD']");
                TempHKD.Ma = "HKD";
                if (HKDNode != null)
                {
                    TempHKD.Mua_CK = HKDNode.Attributes["Buy"].Value;
                    TempHKD.Mua_TM = HKDNode.Attributes["Transfer"].Value;
                    TempHKD.Ban = HKDNode.Attributes["Sell"].Value;
                }
                HKD = TempHKD;



                Price TempJPY = new Price();
                XmlNode JPYNode = doc.SelectSingleNode("ExrateList/Exrate[@CurrencyCode='JPY']");
                TempHKD.Ma = "JPY";
                if (JPYNode != null)
                {
                    TempJPY.Mua_CK = JPYNode.Attributes["Buy"].Value;
                    TempJPY.Mua_TM = JPYNode.Attributes["Transfer"].Value;
                    TempJPY.Ban = JPYNode.Attributes["Sell"].Value;
                }
                JPY = TempJPY;


                Price TempSGD = new Price();
                XmlNode SGDNode = doc.SelectSingleNode("ExrateList/Exrate[@CurrencyCode='SGD']");
                TempHKD.Ma = "SGD";
                if (SGDNode != null)
                {
                    TempSGD.Mua_CK = SGDNode.Attributes["Buy"].Value;
                    TempSGD.Mua_TM = SGDNode.Attributes["Transfer"].Value;
                    TempSGD.Ban = SGDNode.Attributes["Sell"].Value;
                }
                SGD = TempSGD;

                Price TempUSD = new Price();
                XmlNode USDNode = doc.SelectSingleNode("ExrateList/Exrate[@CurrencyCode='USD']");
                TempHKD.Ma = "USD";
                if (USDNode != null)
                {
                    TempUSD.Mua_CK = USDNode.Attributes["Buy"].Value;
                    TempUSD.Mua_TM = USDNode.Attributes["Transfer"].Value;
                    TempUSD.Ban = USDNode.Attributes["Sell"].Value;
                }
                USD = TempUSD;

                //Price TempINR = new Price();
                //TempINR.Ma = listnode[8].ChildNodes[1].InnerText.Trim().ToString();
                //TempINR.Mua_CK = listnode[8].ChildNodes[4].InnerText.Trim().ToString();
                //TempINR.Mua_TM = listnode[8].ChildNodes[3].InnerText.Trim().ToString();
                //TempINR.Ban = listnode[8].ChildNodes[5].InnerText.Trim().ToString();
                //INR = TempINR;
                //Price TempKRW = new Price();
                //TempKRW.Ma = listnode[10].ChildNodes[1].InnerText.Trim().ToString();
                //TempKRW.Mua_CK = listnode[10].ChildNodes[4].InnerText.Trim().ToString();
                //TempKRW.Mua_TM = listnode[10].ChildNodes[3].InnerText.Trim().ToString();
                //TempKRW.Ban = listnode[10].ChildNodes[5].InnerText.Trim().ToString();
                //KRW = TempKRW;

                //Price TempKWD = new Price();
                //TempKWD.Ma = listnode[11].ChildNodes[1].InnerText.Trim().ToString();
                //TempKWD.Mua_CK = listnode[11].ChildNodes[4].InnerText.Trim().ToString();
                //TempKWD.Mua_TM = listnode[11].ChildNodes[3].InnerText.Trim().ToString();
                //TempKWD.Ban = listnode[11].ChildNodes[5].InnerText.Trim().ToString();
                //KWD = TempKWD;

                //Price TempMYR = new Price();
                //TempMYR.Ma = listnode[12].ChildNodes[1].InnerText.Trim().ToString();
                //TempMYR.Mua_CK = listnode[12].ChildNodes[4].InnerText.Trim().ToString();
                //TempMYR.Mua_TM = listnode[12].ChildNodes[3].InnerText.Trim().ToString();
                //TempMYR.Ban = listnode[12].ChildNodes[5].InnerText.Trim().ToString();
                //MYR = TempMYR;

                //Price TempNOK = new Price();
                //TempNOK.Ma = listnode[13].ChildNodes[1].InnerText.Trim().ToString();
                //TempNOK.Mua_CK = listnode[13].ChildNodes[4].InnerText.Trim().ToString();
                //TempNOK.Mua_TM = listnode[13].ChildNodes[3].InnerText.Trim().ToString();
                //TempNOK.Ban = listnode[13].ChildNodes[5].InnerText.Trim().ToString();
                //NOK = TempNOK;

                //Price TempSEK = new Price();
                //TempSEK.Ma = listnode[14].ChildNodes[1].InnerText.Trim().ToString();
                //TempSEK.Mua_CK = listnode[14].ChildNodes[4].InnerText.Trim().ToString();
                //TempSEK.Mua_TM = listnode[14].ChildNodes[3].InnerText.Trim().ToString();
                //TempSEK.Ban = listnode[14].ChildNodes[5].InnerText.Trim().ToString();
                //SEK = TempSEK;

               

                //Price TempTHB = new Price();
                //TempTHB.Ma = listnode[16].ChildNodes[1].InnerText.Trim().ToString();
                //TempTHB.Mua_CK = listnode[16].ChildNodes[4].InnerText.Trim().ToString();
                //TempTHB.Mua_TM = listnode[16].ChildNodes[3].InnerText.Trim().ToString();
                //TempTHB.Ban = listnode[16].ChildNodes[5].InnerText.Trim().ToString();
                //THB = TempTHB;

                



                #endregion


            }
            catch (Exception ex)
            {
                ret = false;
                TLog.WriteErr("ExchangeVietComBank : getExchange", ex.ToString());
            }
            //set lai value moi cho du lieu
            if (ret)
                this.setNewValue();
            //return ret;
        }
        #endregion
    }
}